package bsc.war.form;

import bsc.ejb.entity.DimensionalCut;
import bsc.ejb.entity.Pointer;
import bsc.ejb.entity.Settings;
import bsc.ejb.metadata.Comparation;
import bsc.ejb.metadata.Framework;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.BSCUtils;
import bsc.war.service.ScoreCardUtils;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

//org.apache.commons.validator.GenericValidator
/**
 *
 * @author Miguel Angel
 */
public class CalculateData extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        boolean result = true;// = "Actualización de Datos Exitosa";
        try {

            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");            

            /*Long idDimensionalCut = Long.parseLong(request.getParameter("scoreCard"));
            DimensionalCut pointerDimensionalCut = delegate.findDimensionalCut(idDimensionalCut);*/

            Long idPointer = Long.parseLong(request.getParameter("scoreCard"));
            Pointer pointer = (Pointer)delegate.findScoreCard(idPointer);
            
            //Se generan los rangos de fechas (para la primera versión de Entry Data
            List<Date> dates = ScoreCardUtils.generateDatesRange(request, pointer);

            result = BSCUtils.calculateScoreCard(delegate, pointer, dates);

           
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }
        request.setAttribute("result", result);
        return new ModelAndView("result");
    }
}
